<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

<title>菜单管理</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="css/global.css" media="all">
<link rel="stylesheet"
	href="plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="css/table.css" />
</head>

<body>
	<div class="admin-main">

		<blockquote class="layui-elem-quote">
			<a href="javascript:;" class="layui-btn layui-btn-small" id="add">
				<i class="layui-icon">&#xe608;</i> 添加信息
			</a> <a href="#" class="layui-btn layui-btn-small" id="import"> <i
				class="layui-icon">&#xe608;</i> 导入信息
			</a> <a href="#" class="layui-btn layui-btn-small"> <i
				class="fa fa-shopping-cart" aria-hidden="true"></i> 导出信息
			</a> <a href="#" class="layui-btn layui-btn-small" id="getSelected">
				<i class="fa fa-shopping-cart" aria-hidden="true"></i> 获取全选信息
			</a> <a href="javascript:;" class="layui-btn layui-btn-small" id="search">
				<i class="layui-icon">&#xe615;</i> 搜索
			</a>
		</blockquote>
		<fieldset class="layui-elem-field">
			<legend>数据列表</legend>
			<div class="layui-field-box layui-form">
				<table class="layui-table admin-table">
					<colgroup>
						<col width="50">
						<col width="150">
						<col width="150">
						<col width="200">
						<col>
					</colgroup>
					<thead>
						<tr>
							<th style="width: 30px;"><input type="checkbox"
								lay-filter="allselector" lay-skin="primary"></th>
							<th>ID</th>
							<th>名称</th>
							<th>菜单路径</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="content"></tbody>
				</table>
				<div id="songpeng" align='center'></div>
			</div>
		</fieldset>
		<div class="admin-table-page">
			<div id="paged" class="page"></div>
		</div>
	</div>
	<!--模板-->
	<script id="template" type="text/html" >
			{{# layui.each(d.list, function(index, item){ }}
			<tr>
				<td><input type="checkbox" name="{{ item.id }}" lay-skin="primary"></td>
				<td>{{ item.id }}</td>
				<td>{{ item.name }}</td>
				<td>{{ item.path }}</td>
				<td>
					<a href="/detail-1" target="_blank" class="layui-btn layui-btn-normal layui-btn-mini">预览</a>
					<a href="javascript:;" data-name="{{ item.id }}" data-opt="edit" class="layui-btn layui-btn-mini">编辑</a>
					<a href="javascript:;" data-id="1" data-opt="del" class="layui-btn layui-btn-danger layui-btn-mini">删除</a>
				</td>
			</tr>
			{{# }); }}
		</script>
	<script type="text/javascript" src="plugins/layui/layui.js"></script>
	<script>
		
		layui.use([ 'laypage', 'layer','laytpl','form' ], function() {
			var laypage = layui.laypage, layer = layui.layer, laytpl = layui.laytpl, form = layui.form();
			var $ = layui.jquery;
			
			$(function(){
				$.ajax({	
	                type: "POST",
	                url: "system/SysMenu_loadSysMenuGrid.action",
	                data: '',
	                success: function (data) {
	                	 var data = JSON.parse(data);
	                	var pagesVal= Math.ceil(data.list.length/3);
	                	var groupsVal = 5;
	                	if(pagesVal <=5){
	                		groupsVal = pagesVal;
	                	}
	                	laypage({
	        				cont: 'songpeng',
	        				pages: pagesVal,
	        				groups: groupsVal,
	        			    skin: '#1E9FFF',
	        				skip: true,
	        				jump: function(obj, first) {
	        					if (!first) {
	        						layer.msg('第 ' + obj.curr + ' 页');
	        					}
	        					$.ajax({	
	        		                type: "POST",
	        		                url: "system/SysMenu_loadSysMenuGrid.action",
	        		                data: "page="+obj.curr,
	        		                success: function (data) {
	        		                    var data = JSON.parse(data);
	        		                    obj.pages = 3;
	        		                    obj.groups = 2
	        		                    var tpl = template.innerHTML;
	        		                    laytpl(tpl).render(data, function(result){
	        		        				content.innerHTML = result;
	        		        			  });
	        		                    form.render('checkbox');
	        		                },
	        		                error: function () {
	        		                	layer.msg('模块加载异常！');
	        		                }
	        		            });
	        				}
	        			});
	                },
	                error: function () {
	                	layer.msg('模块加载异常！');
	                }
	            });
			});
			//全选
			 form.on('checkbox(allselector)', function(data){
			    var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
			    child.each(function(index, item){
			      item.checked = data.elem.checked;
			    });
			    form.render('checkbox');
			  });
		});
	</script>
</body>

</html>